using System;
using System.Collections.Generic;

namespace AuthorizeNET {
	public class Transaction {
		private MerchantConfiguration merchant;
		private TransactionDetails details;
		private ExtendedDetails extended_details;
		private Customer customer;
		private ResponseConfig response_config;
		private ShippingDetails shipping;
		
		public Transaction() { }

		public MerchantConfiguration Merchant {
			get { return (this.merchant); }
			set { this.merchant = value; }
		}

		public TransactionDetails Details {
			get { return (this.details); }
			set { this.details = value; }
		}

		public ExtendedDetails ExtendedDetails {
			get { return (this.extended_details); }
			set { this.extended_details = value; }
		}

		public Customer Customer {
			get { return (this.customer); }
			set { this.customer = value; }
		}

		public ResponseConfig ResponseConfig {
			get { return (this.response_config); }
			set { this.response_config = value; }
		}

		public ShippingDetails Shipping {
			get { return (this.shipping); }
			set { this.shipping = value; }
		}

		public String SerializeRequest() {
			List<String> lines = new List<string>();

			if (merchant != null) lines.Add(NameValueSerializer.Serialize(merchant));
			if (details != null) lines.Add(NameValueSerializer.Serialize(details));
			if (extended_details != null) lines.Add(NameValueSerializer.Serialize(extended_details));
			if (customer != null) lines.Add(NameValueSerializer.Serialize(customer));
			if (response_config != null) lines.Add(NameValueSerializer.Serialize(response_config));
			if (shipping != null) lines.Add(NameValueSerializer.Serialize(shipping));

			string request = String.Join("&", lines.ToArray());
			return (request);
		}
	}
}
